﻿using System;
using System.Collections;

namespace YArchitech.HCLoad.XmlData
{
	public class KeyFloorTables : Hashtable
	{
		public KeyFloorTables(Building building)
		{
			this.parent = building;
		}

		public Building Parent
		{
			get
			{
				return this.parent;
			}
			set
			{
				this.parent = value;
			}
		}

		public int AddKeyFloorTable(KeyFloorTable keyFloorTable)
		{
			int result;
			try
			{
				keyFloorTable.Parent = this;
				int num = this.parent.Parent.Parent.Parent.AddCurrID();
				keyFloorTable.ID = num;
				this.Add(num, keyFloorTable);
				this.parent.Parent.Parent.Parent.hCurrIDList.Add(num, keyFloorTable);
				result = num;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public void RemoveKeyFloorTable(int ID)
		{
			try
			{
				this.Remove(ID);
				this.parent.Parent.Parent.Parent.hCurrIDList.Remove(ID);
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public KeyFloorTable GetKeyFloorTable(int ID)
		{
			KeyFloorTable result;
			try
			{
				result = (KeyFloorTable)this[ID];
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public bool LoadKeyFloorTable(KeyFloorTable keyFloorTable)
		{
			bool result;
			try
			{
				keyFloorTable.Parent = this;
				int id = keyFloorTable.ID;
				if (this.parent.Parent.Parent.Parent.hCurrIDList.ContainsKey(id))
				{
					result = false;
				}
				else
				{
					if (id > this.parent.Parent.Parent.Parent.CurrID)
					{
						this.parent.Parent.Parent.Parent.CurrID = id;
					}
					this.Add(id, keyFloorTable);
					this.parent.Parent.Parent.Parent.hCurrIDList.Add(id, keyFloorTable);
					result = true;
				}
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		private Building parent;
	}
}
